var config = require('../../../utils/config');
var util = require('../../../utils/util');
var WxParse = require('../../../wxParse/wxParse.js');
var storeAPI = require('../../../utils/store');
var API_URL = config.API_URL;
var id, typeId;
var get_news = function (that) {
  my.httpRequest({
    url: API_URL.news,
    data: {
      id: id,
      typeId: typeId,
    },
    method: 'POST',
    success: function (res) {
      console.log(res)
      var data = res.data.data
      that.setData(data);
      var article = data.news.content.replace(/\/editor\//g, 'http://wenzhang.jade-box.com/editor/');
      WxParse.wxParse('article', 'html', article, that, 11);
    },
    fail: function () {
     my.alert({
         title:"网络出错了"
     })
    },
    complete: function () {
  my.hideLoading();
    }
  })
}
Page({
  data: {},
  onLoad: function (options) {
    // 拿到跳转前页面的详情页ID，和种类 值执行发送数据
    id = options.id;
    typeId = options.typeId;
    console.log(id + ',' + typeId);
    // my.showToast({
    //  content: '加载中',
    //   type: 'loading',
    //   duration: 1000,

    // })
    my.showLoading({
     content: '加载中'
   
    });
    get_news(this);
  },
  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {
    // 页面显示
  },
  onHide: function () {
    // 页面隐藏
  },
  onUnload: function () {
    // 页面关闭
  },
  news: function (e) {
    var id = e.currentTarget.dataset.id;
    var typeId = e.currentTarget.dataset.type;
    my.redirectTo({
      url: '/pages/article/news/news?id=' + id + '&typeId=' + typeId
    })
  },
  // 点击更多 跳转
  more: function () {
    var pages = getCurrentPages();
    console.log(pages)
    var delta;
    var hasList = false;
    for (var i = 0; i < pages.length; i++) {
      if (pages[i].__route__ == "pages/article/news_list/news_list") {
        delta = pages.length - 1 - i;
        hasList = true;
      }
    }
    if (hasList) {
      my.navigateBack({
        delta: delta,
      })
    } else {
      my.navigateTo({
        url: '/pages/article/news_list/news_list',

      })
    }
  }
})